//
// Created by win10 on 2024/11/13.
//
#include <stdio.h>
#include <stdlib.h>

typedef struct queueNode{
  int data;
  struct queueNode *next;
}queueNode;

typedef struct queue{
  queueNode *front, *rear;
}queue;

int isEmpty(queue *q) {
    return q->front == NULL;
}
void enqueue(queue *q, int value) {
  queueNode *newNode = (queueNode *)malloc(sizeof(queueNode));
  newNode->data = value;
  newNode->next = NULL;
  if(isEmpty(q)) {
    q->front = newNode;
    q->rear = newNode;
  }else{
    q->rear->next = newNode;
    q->rear = newNode;
  }
}
int dequeue(queue *q){
  if(isEmpty(q)){
    return -1;
  }
  queueNode *front = q->front;
  int value = front->data;
  q->front = front->next;
  free(front);
  return value;
}
int initQueue(queue *q){
  q->front = q->rear = NULL;
  return 0;
}
int main() {
  int t,n,m;
  scanf("%d",&t);
  queue *q = (queue *)malloc(sizeof(queue));
  initQueue(q);
  for (int i = 0; i < t; ++i) {
    scanf("%d",&n);
    if (n == 1) {
      scanf("%d",&m);
      enqueue(q, m);
    }else {
      m = dequeue(q);
      if (m != -1) {
        printf("%d\n",m);
      } else {
        printf("invalid\n");
      }
    }
  }
}